home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: cwi.nl!dik
- From: dik@cwi.nl (Dik T. Winter)
- Subject: Re: Nedd help!!! <depth of recursion>
- Message-ID: <DnxDzy.HL0@cwi.nl>
- Sender: news@cwi.nl (The Daily Dross)
- Nntp-Posting-Host: chrysant.cwi.nl
- Organization: CWI, Amsterdam
- References: <JSA.96Mar7145352@organon.com> <Pine.SUN.3.91.960307161803.17639A-100000@thomas.helios.nd.edu> <4hnrol$5ts@umbc9.umbc.edu>
- Date: Fri, 8 Mar 1996 01:40:45 GMT
-
- In article <4hnrol$5ts@umbc9.umbc.edu> schlein@umbc.edu (Jonas J. Schlein) writes:
- [ About the Ackerman function ].
- > |> My problem is computing the depth of recursion of the procedure <Ack(m,n)>.
- > |> Ack(m,n) = {n+1 if m=0
- > |> Ack(m-1,n) if n=0
- > |> Ack(m-1,Ack(m,n-1) }
- [ Note, this is not the true Ackerman function; the last line is wrong and
- should read "Ack(m-1,Ack(m,n-1)+1)}" I think.]
-
- > Well I highly suspect this is a homework assignment since you are
- > posting from a *.edu site. However, I will give you this hint...Add
- > a global variable to your program called 'depth' and increment it everytime
- > Ack() is called.
-
- This will not count the depth but the number of calls. To count the
- depth you need two globals. A question is of course how the third line
- ought to count with respect to recursion depth. Should the Ack in
- the parameter list counter deeper in recursion as the plain Ack or not?
- (In old times this was indeed also called recursion, currently it is
- different I think.)
-
- Another hint, do not try the function with large parameters (like integers
- exceeding 3 or something like that). And make the globals long's if your
- int's are only 16 bits. (With the redefinition Ack(3,2) gives a depth of
- 32770; which looks about right.)
-
- Note: in the modified definition Ack(0,n) == n + 1; Ack(1,n) == 2*(n+2) - 3
- and Ack(2,n) == 2**(n+2) - 3 which is as I remember it.
- (** is exponentiation.)
- --
- dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924098
- home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
-